package com.aglhz.nature.view;

import com.aglhz.nature.R;
import com.aglhz.nature.presenter.MyselfPresenter;
import com.aglhz.nature.presenter.PersonDataPresenter;
import com.aglhz.nature.view.iv.PersonDataView;
import com.squareup.picasso.Picasso;
import com.umeng.socialize.utils.Log;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
/**
 * 完善个人资料
 * @author Administrator
 *
 */
public class PersonDataActivity extends Activity implements PersonDataView{
	
	private PersonDataPresenter presenter;
	
	private SharedPreferences sharedPreferences;  
	private String refresh_token;
	private String openid;
	private String access_token;
	private String  nickname;
	private String headimgurl;
	private String unionid;
	private String token;
	
	
	private ImageView headimage;
	private EditText userName;
	private EditText address;
	private EditText provinceIdprovinceId;
	private EditText cityId;
	private EditText areaId;
	private EditText qq_number;
	private EditText birthday;
	private EditText userSex;
	private Button submit;
	
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.persondata);			
				
		//获取sharedPreferences里面的信息
				sharedPreferences =getSharedPreferences("WX_INFO", Context.MODE_PRIVATE);
				refresh_token=sharedPreferences.getString("refresh_token", "");	
				openid=sharedPreferences.getString("openid", "");
				access_token=sharedPreferences.getString("access_token", "");
				nickname=sharedPreferences.getString("nickname", "");
				headimgurl=sharedPreferences.getString("headimgurl", "");
				unionid=sharedPreferences.getString("unionid", "");
				token=sharedPreferences.getString("token", "");
				Log.e("shujulaile -------------------",openid+"============"+refresh_token);
				
				
				//
				 headimage=(ImageView) findViewById(R.id.headimage);
				 userName=(EditText) findViewById(R.id.userName);
				 address=(EditText) findViewById(R.id.address);
				 provinceIdprovinceId=(EditText) findViewById(R.id.provinceIdprovinceId);
				 cityId=(EditText) findViewById(R.id.cityId);
				 areaId=(EditText) findViewById(R.id.areaId);
				 qq_number=(EditText) findViewById(R.id.qq_number);
				 birthday=(EditText) findViewById(R.id.birthday);
				 userSex =(EditText) findViewById(R.id.userSex);
				 submit=(Button) findViewById(R.id.submit);
				 
				 //提交数据
				 submit.setOnClickListener(new OnClickListener() {
					
					@Override
					public void onClick(View arg0) {
						presenter.submitInfo();
						
					}
				});
				 
				presenter = new PersonDataPresenter(this);
				// basePresenter register
				presenter.register();
				presenter.loadInfo();
	}

	@Override
	public String setRefresh_token() {
		return refresh_token;
	}

	@Override
	public String setOpenid() {
		return openid;
	}

	@Override
	public String setAccess_token() {
		return access_token;
	}

	@Override
	public String setNickname() {
		return nickname;
	}

	@Override
	public String setHeadimgurl() {
		return headimgurl;
	}

	@Override
	public String setUnionid() {
		return unionid;
	}

	
	

	@Override
	public void setHeadimage(String url) {
		Picasso.with(this).load(url)
        .error(R.drawable.ic_launcher).into(headimage);
		
	}

	@Override
	public void setUserName(String name) {
		userName.setText(name);
		
	}
	
	
	@Override
	public void onDestroy() {
		super.onDestroy();
		presenter.unregister();
	}
}
